/*
 * @Author: chenr 526963089@qq.com
 * @Date: 2023-03-01 16:05:54
 * @LastEditors: chenr 526963089@qq.com
 * @LastEditTime: 2023-03-01 17:26:59
 * @FilePath: /library-web/src/src-portal/hooks/useUpdateRouter.ts
 * @Description: 更新路由
 */
import { watch } from 'vue';
import { useRouterStore } from '../stores/async-routers';
import { useUserStore } from '../stores/user';
import { storeToRefs } from 'pinia';

export default () => {
  /**
   * @description: 登陆 或者 退出登陆了重新获取路由
   * @return {*}
   */
  const userStore = useUserStore();
  const routerStore = useRouterStore();
  const { user_id } = storeToRefs(userStore);
  const updateRouter = () => {
    watch(user_id, () => {
      routerStore.removeState();
    });
  };
  return {
    createUpdateRouter: updateRouter,
  };
};
